home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-3.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  778b  |  28 lines

  1. ;
  2. ; *** Listing 7-3 ***
  3. ;
  4. ; Calculates the 16-bit sum of all bytes in a 128Kb block
  5. ; using optimized code that takes advantage of the knowledge
  6. ; that the first byte summed is at offset 0 in its segment.
  7. ;
  8. ; Time with LZTIME.BAT, since this takes more than
  9. ; 54 ms to run.
  10. ;
  11.     call    ZTimerOn
  12.     sub    bx,bx    ;we'll just sum the 128Kb starting
  13.             ; at DS:0
  14.     mov    cx,2    ;count two 64Kb blocks
  15.     mov    ax,bx    ;set initial sum to 0
  16.     mov    dh,ah    ;set DH to 0 for summing later
  17. SumLoop:
  18.     mov    dl,[bx]    ;get this byte
  19.     add    ax,dx    ;add the byte to the sum
  20.     inc    bx    ;point to the next byte
  21.     jnz    SumLoop    ;go until we wrap at the end of a
  22.             ; 64Kb block
  23.     mov    si,ds
  24.     add    si,1000h ;advance the segment by 64K bytes
  25.     mov    ds,si
  26.     loop    SumLoop    ;count down 64Kb blocks
  27.     call    ZTimerOff
  28.